/* 
 * Copyright(C) Triniforce 
 * All Rights Reserved. 
 * 
 */ 

package com.triniforce.fototools.inv;

import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

import org.apache.commons.math3.stat.descriptive.SummaryStatistics;

import com.triniforce.db.test.TFTestCase;

public class FirstTest extends TFTestCase {
	
	public void test() throws IOException{
		long start = System.currentTimeMillis();
		BufferedImage img = null;
		img = ImageIO.read(new File("D:/Development/triniforce/bin/foto-tools/DSC_4552.jpg"));
		trace(img.getPropertyNames());
		trace("w: " + img.getWidth() + " h:" + img.getHeight());
		int cnt = 0;
		{
			SummaryStatistics s = new SummaryStatistics();
			int lastRGB = 0;
			int part = 10;
			int startX = img.getWidth()/2 - img.getWidth()/part/2;
			int startY = img.getHeight()/2 - img.getHeight()/part/2;
			for (int x = startX; x < startX + img.getWidth()/part; x++) {
				for (int y = startY; y < startY + img.getHeight()/part; y++) {
					lastRGB = img.getRGB(x, y);
					Color c = new Color(lastRGB);
					Double l = 0.2126 * c.getRed() + 0.7152 * c.getGreen() + 0.0722 * c.getBlue();
					s.addValue(l);
					cnt++;
				}
				//trace(lastRGB);
			}
			trace("Mean:" + s.getMean());
			trace("Std dev:" + s.getStandardDeviation());
		}
		trace("Part Pixels:" + cnt + " time=" + (System.currentTimeMillis() - start));
		
//		{
//			int cnt = 0;
//			int lastRGB = 0;
//			long start = System.currentTimeMillis();
//			for (int x = 0; x < img.getWidth(); x++) {
//				for (int y = 0; y < img.getHeight(); y++) {
//					lastRGB = img.getRGB(x, y);
//					cnt++;
//				}
//				//trace(lastRGB);
//			}
//			trace("Pixels:" + cnt + " time=" + (System.currentTimeMillis() - start));
//		}
		 
	}

}
